<?php
namespace Dashboard\Controller;
class CompanyController extends BaseController{
    public function index(){
        $list             = sel("company");
        $list['intro']   = html_entity_decode($list['intro']);
        $list['content'] = html_entity_decode($list['content']);
        $this->assign("list",$list);
        $this->display();
    }
    public function form(){
        $test = sel("company");
        if($test){
            $this->assign("list",$test);
        }
        $this->display();
    }
   /* public function add(){
        $id      = I('id');$data['jing']   = I("jing");$data['wei']   = I("wei"); $data['y_time']   = I("y_time");
        $data['intro']   = I("intro");$data['address']   = I("address");$data['phone']   = I("phone");$data['name']   = I("name");
        if(!$id){
            //处理图片
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
                $data['three'] = $image['info']['2'];
                $data['create_at']   = time();
                $res = ins("company",$data);
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."添加了公司信息";
                $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
                $this->success("添加成功",U('index'));
            }else{
                $this->success("图片请添加完整",U('form'));
            }
        }else{
            $o = I('o');$t = I('t');$h = I('h');
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
                unlink($o);unlink($t);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }

                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
                $data['three'] = $image['info']['2'];

            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] == null){
                $os = explode(",",$o);
                $coun = count($os);
                for($i=0;$i<$coun;$i++){
                    unlink($os[$i]);
                }
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = implode(",",$image['info']);
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] == null){
               unlink($t);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['two']   = $image['info']['0'];
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] != null){
                unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['three'] = $image['info']['0'];
            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] == null){
                unlink($o);unlink($t);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
               unlink($t);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['two']   = $image['info']['0'];
                $data['three'] = $image['info']['1'];
            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] != null){
                unlink($o);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['three'] = $image['info']['1'];
            }
            $data['up_at']   = time();
            $res = up_one("company",array("id"=>$id),$data);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."修改了公司信息";
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->success("修改成功",U('index'));
        }
    }*/
    public function add(){
        $id      = I('id');$data['jing']   = I("jing");$data['wei']   = I("wei"); $data['y_time']   = I("y_time");
        $data['intro']   = I("intro");$data['address']   = I("address");$data['phone']   = I("phone");$data['name']   = I("name");
        if(!$id){
            //处理图片
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
                $data['three'] = $image['info']['2'];
                $data['create_at']   = time();
                $res = ins("company",$data);
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."添加了公司信息";
                $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
                $this->success("添加成功",U('index'));
            }else{
                $this->success("图片请添加完整",U('form'));
            }
        }else{
            $o = I('o');$t = I('t');$h = I('h');
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
                unlink($o);unlink($t);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
                $data['three'] = $image['info']['2'];

            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] == null){
                unlink($o);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] == null){
                unlink($t);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['two']   = $image['info']['0'];
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] != null){
                unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['three'] = $image['info']['0'];
            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] == null){
                unlink($o);unlink($t);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['two']   = $image['info']['1'];
            }
            if($_FILES['one']['name']['0'] == null && $_FILES['two']['name']['0'] != null && $_FILES['three']['name']['0'] != null){
                unlink($t);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['two']   = $image['info']['0'];
                $data['three'] = $image['info']['1'];
            }
            if($_FILES['one']['name']['0'] != null && $_FILES['two']['name']['0'] == null && $_FILES['three']['name']['0'] != null){
                unlink($o);unlink($h);
                $image = $this->imgUps("company/");
                $count  = count($image['thumb']);
                for($i=0;$i<$count;$i++){
                    unlink($image['thumb'][$i]);
                }
                $data['one']   = $image['info']['0'];
                $data['three'] = $image['info']['1'];
            }
            $data['up_at']   = time();
            $res = up_one("company",array("id"=>$id),$data);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."修改了公司信息";
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->success("修改成功",U('index'));
        }
    }
    //协议
    public function xie(){
        $test = sels("xie");
        $this->assign("list",$test);
        $this->display();
    }
    public function xie_form(){
        $id = I('id');
        if($id){
            $list = sel("xie"," * ","id = {$id}");
            $this->assign("list",$list);
        }
        $this->display();
    }
    public function xie_add(){
        $id      = I('id');
        $status   = I("status");
        $content = I("content");
        if(!$content){
            $this->ajaxReturn(array("status"=>1,"info"=>"信息填写不完整"));
        }else{
            if($id == 0){
                $res = ins("xie",array("status"=>$status,"content"=>$content,"create_at"=>time()));
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."添加了协议";
                $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
                $this->ajaxReturn(array("status"=>2,"info"=>"添加成功"));
            }else{
                $res = up_one("xie",array("id"=>$id),array("status"=>$status,"content"=>$content,"create_at"=>time()));
                $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."修改了协议";
                $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
                $this->ajaxReturn(array("status"=>2,"info"=>"修改成功"));
            }
        }
    }
    //积分数
    public function covers(){
        $test = sels("covers_shu");
        $this->assign("list",$test);
        $this->display();
    }
    public function covers_form(){
        $id = I('id');
        if($id){
            $list = sel("covers_shu"," * ","id = {$id}");
            $this->assign("list",$list);
        }
        $this->display();
    }
    public function covers_add(){
        $id                  = I('id');
        $data['nums_one']    = I("nums_one");
        $data['nums_two']    = I("nums_two");
        $data['nums_three']    = I("nums_three");
        $data['nums_four']    = I("nums_four");
        $data['nums_five']    = I("nums_five");
        $data['nums_six']    = I("nums_six");
        $data['nums_seven']    = I("nums_seven");
        $data['nums_eight']    = I("nums_eight");
        if(!$id){
            $res = ins("covers_shu",$data);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."添加了协议";
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->ajaxReturn(array("status"=>2,"info"=>"操作成功"));
        }else{
            $data['create__at'] = time();
            $res = up_one("covers_shu",array("id"=>$id),$data);
            $content = "管理员：".$_SESSION['admin']['numbers']." 于 ".date("Y-m-d H:i:s",time())."修改了积分数";
            $log     = ins("logs",array("content"=>$content,"admin_id"=>$_SESSION['admin']['id'],"create_at"=>time()));
            $this->ajaxReturn(array("status"=>2,"info"=>"操作成功"));
        }
    }
}